global class BatchInsertFraudLeadData implements Database.Batchable<sObject> {
	global string query;
	global BatchInsertFraudLeadData() {
		/*Datetime date_range = system.now().addYears(-1);
		List<Fraud_Report_Data__c> delFraudData = [Select id from Fraud_Report_Data__c];
		if(delFraudData.size()>0)
			delete delFraudData;
			*/
		query = 'Select FirstName,Middle_Name__c,LastName,Lead_ID__c,Lead_Creation_Date__c,' +
			           'Home_Phone__c,Other_Phone__c,Work_Phone__c,Other_Phone_2__c,'+
                       'MobilePhone,Fax,Street,City,State,PostalCode,Other_Street__c,'+
                       'Other_City__c,Other_State__c,Other_Postal_Code__c,Personal_Email__c,Other_Email__c,'+
                       'Work_Email__c,Other_Email_2__c,University_Email__c,l.Program__r.External_ID_1__c,Campus__r.External_ID_2__c,'+
                       'l.Fraud_Enrollment_Status__c,LeadSource,Anticipated_Start_Date__c,Birth_Date__c, l.Fraud_Flag__c,Status'+  
                 ' From Lead l' + 
                 ' where l.RecordType.Name =' + '\'West - Prospective Student\'' + 
                 ' and l.IsConverted = false and l.Lead_Creation_Date__c = LAST_N_DAYS:365';
	}
	
	global Database.Querylocator start(Database.BatchableContext BC) {
		return Database.getQueryLocator(query);
	}
	
	global void execute(Database.BatchableContext BC,List<Lead> insertFraudLeads) {
		
		setFraudDataLead(insertFraudLeads);
	}
	
	global void finish(Database.BatchableContext BC) {
		
	}
	
	public void setFraudDataLead(List<Lead> lstFraudLead) {
        List<Fraud_Report_Data__c> lstFraudReportDataLead = new List<Fraud_Report_Data__c>();
        
        for(Lead l : lstFraudLead){
        	system.debug('Got Here 55');
            Fraud_Report_Data__c tempFF = new Fraud_Report_Data__c();
            tempFF.First_Name__c = l.FirstName;
            tempFF.Middle_Name__c = l.Middle_Name__c;
            tempFF.Last_Name__c = l.LastName;
            tempFF.IRN__c = l.Lead_ID__c;
            tempFF.Lead_Create_Date__c = l.Lead_Creation_Date__c.format('MM/dd/yyyy');
            tempFF.Home_Phone__c = l.Home_Phone__c;
            tempFF.Home2_Phone__c = l.Other_Phone__c;
            tempFF.Business_Phone__c = l.Work_Phone__c;
            tempFF.Business2_Phone__c = l.Other_Phone_2__c;
            tempFF.Mobile_Phone__c = l.MobilePhone;
            tempFF.Home_Fax_Phone__c = l.Fax;
            tempFF.Home_Address_Line_1__c = l.Street;
            tempFF.Home_City__c = l.City;
            tempFF.Home_State__c = l.State;
            tempFF.Home_Zip__c = l.PostalCode;
            tempFF.Business_Address_Line_1__c = l.Other_Street__c;
            tempFF.Business_City__c = l.Other_City__c;
            tempFF.Business_State__c = l.Other_State__c;
            tempFF.Business_Zip__c = l.Other_Postal_Code__c;
            tempFF.Home_Email__c = l.Personal_Email__c;
            tempFF.Home2_Email__c = l.Other_Email__c;
            tempFF.Business_Email__c = l.Work_Email__c;
            tempFF.Business2_Email__c = l.Other_Email_2__c;
            tempFF.Student_Email__c = l.University_Email__c;
            tempFF.Program_F__c = l.Program__r.External_ID_1__c;
            tempFF.Home_Campus__c = l.Campus__r.External_ID_2__c;
            tempFF.Enrollment_Status__c = l.Fraud_Enrollment_Status__c;
            tempFF.Primary_Lead_Source__c = l.LeadSource;            
            tempFF.Anticipated_Start_Date__c = l.Anticipated_Start_Date__c!=null?l.Anticipated_Start_Date__c.format(): '';
            tempFF.Birth_Date__c = l.Birth_Date__c!=null?l.Birth_Date__c.format():'';
            tempFF.Fraud_Flag__c = l.Fraud_Flag__c;
            lstFraudReportDataLead.add(tempFF);   
        }
        if(lstFraudReportDataLead.size()>0)
        	insert lstFraudReportDataLead;
    }
}